<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->

    <title>学校信息查看与管理系统</title>


    <!-- Bootstrap -->
    <link href="/webjars/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="/webjars/jquery/3.5.1/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>

<!--    点击按钮弹出修改表单-->
    <script>$('#myModal1').modal(show);
    $('#myModal2').modal(show);
    $('#myModal3').modal(show);

    function deleteGrade(grade_id) {
        $('#gradeid').val(grade_id);
    }

    function updateGrade(grade_id,score,grade_term,subject_name) {
        $('#updateGradeid').val(grade_id);
        $('#updateGradescore').val(score);
        $('#updateGradeterm').val(grade_term);
        $('#updateSubject').text(subject_name);
    }
    </script>

</head>
<body>
<!--引入导航条-->
<div th:replace="~{departmentAdminPages/index::nav}"></div>

<!--表格-->
<table class="table table-hover">
    <thead>
    <th>学生姓名</th>
    <th>所属系</th>
    <th>科目</th>
    <th>分数</th>
    <th>学期</th>
    <th>操作</th>
    </thead>

    <tr th:each="grade:${gradeList}">
        <td th:text="${grade.student.student_name}"></td>
        <td th:text="${grade.student.department.department_name}"></td>
        <td th:text="${grade.subject.subject_name}"></td>
        <td th:text="${grade.score}"></td>
        <td th:text="${grade.term}"></td>
        <td><button type="button" class="btn btn-info btn-round btn-xs" data-toggle="modal" data-target="#myModal1" th:onclick="updateGrade([[${grade.grade_id}]],[[${grade.score}]],[[${grade.term}]],[[${grade.subject.subject_name}]])">
                          <i class="glyphicon"></i>修改 </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="deletebutton" class="btn btn-danger btn-round btn-xs" data-toggle="modal" data-target="#myModal3" th:onclick="'javascript:deleteGrade(\''+${grade.grade_id}+'\');'">删除</button></td>

        <!--详情按钮的弹出框 -->
          <div class="modal fade" id="myModal1">
                      <div class="modal-dialog">
                      <div class="modal-content">
                      <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                      <h4 class="modal-title">编辑该学生成绩信息</h4>
                      </div>
                      <div class="modal-body">

        <form class="form-horizontal" th:method="post" th:action="@{/grade/update}">
            <input type="hidden" name="_method" value="put" />
            <input type="hidden" name="grade_id" value="" id="updateGradeid"/>
            <input type="hidden" th:name="student_username" th:value="${grade.student.student_username}"/>
<!--            <input type="hidden" th:name="subject" th:value="${grade.subject}"/>-->

            <div class="form-group">
                <label class="col-sm-2 control-label">科目</label>
                <div class="col-sm-10">
                    <p class="form-control-static" id="updateSubject" text="" ></p>
                </div>
            </div>


            <div class="form-group">
                <label for="updateGradescore" class="col-sm-2 control-label">分数</label>
                <div class="col-sm-10">
                    <input type="number" name="score"  value=""  class="form-control" id="updateGradescore">
                </div>
            </div>

            <div class="form-group">
                <label for="updateGradeterm" class="col-sm-2 control-label">学期</label>
                <div class="col-sm-10">
                    <input type="text" name="term"  value="" id="updateGradeterm" class="form-control">
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-default">修改</button>
                </div>
            </div>

        </form>
                      </div>
                      </div>
                      </div>
          </div>

        <!--确定删除的弹出框-->
          <div class="modal fade" id="myModal3">
                      <div class="modal-dialog">
                      <div class="modal-content">
                      <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                      <h4 class="modal-title">是否删除该条成绩记录</h4>
                      </div>
                      <div class="modal-body">
        <form th:method="post" th:action="@{/grade/delete}">
            <input type="hidden" name="_method" value="delete" />
            <input type="hidden" name="grade_id" id="gradeid" value=""/>
            <input type="submit" value="是"/>
        </form>
                      </div>
                      </div>
                      </div>
          </div>

    </tr>

</table>

<hr/>

<p>
    <button type="button" class="btn btn-primary btn-xs"  data-toggle="modal" data-target="#myModal2">添加该学生成绩信息</button>
</p>

<!--添加成绩的弹出框 -->
  <div class="modal fade" id="myModal2">
                  <div class="modal-dialog">
                  <div class="modal-content">
                  <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                  <h4 class="modal-title">添加该学生成绩信息</h4>
                  </div>
                  <div class="modal-body">
    <form class="form-horizontal" th:method="post" th:action="@{/grade/add}">
        <input type="hidden" th:value="${requestStudent.student_id}" th:name="student_id"/>

        <div class="form-group">
            <label class="col-sm-2 control-label">学生姓名</label>
            <div class="col-sm-10">
                <p class="form-control-static" th:text="${requestStudent.student_name}"></p>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">科目</label>
            <div class="col-sm-10">
                <select th:name="subject_id">
                    <option th:each="subject:${subjectList}" th:value="${subject.subject_id}" th:text="${subject.subject_name}"></option>
                </select>
            </div>
        </div>


        <div class="form-group">
            <label for="inputscore3" class="col-sm-2 control-label">分数</label>
            <div class="col-sm-10">
                <input type="number" class="form-control" id="inputscore3" th:name="score">
            </div>
        </div>

        <div class="form-group">
            <label for="inputterm3" class="col-sm-2 control-label">学期</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="inputterm3" th:name="term">
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-default">修改</button>
            </div>
        </div>

    </form>
                  </div>
                  </div>
                  </div>
      </div>


</body>
</html>